package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderOperateHistoryEntity;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author guoch0613@163.com
 * @Description
 * @create 2021-05-10 18:29
 */
@Controller
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMsg")
    public String sendMessage() {
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                OrderReturnReasonEntity orderReturnReasonEntity = new OrderReturnReasonEntity();
                orderReturnReasonEntity.setId(1L);
                orderReturnReasonEntity.setName("guoch");
                orderReturnReasonEntity.setStatus(1);
                rabbitTemplate.convertAndSend("java_direct_exchange", "javatest", orderReturnReasonEntity);
            } else {
                OrderOperateHistoryEntity orderEntity = new OrderOperateHistoryEntity();
                orderEntity.setId(1L);
                orderEntity.setOperateMan("guoch");
                orderEntity.setOrderStatus(1);
                rabbitTemplate.convertAndSend("java_direct_exchange", "javatest", orderEntity);
            }
        }
        return "";

    }
}
